1
|
|
|
const httpProcessor = require('../HttpProcessor'); |
2
|
|
|
const services = require('../config/services'); |
3
|
|
|
const constants = require('../config/constants'); |
4
|
|
|
|
5
|
|
|
class Appruve |
6
|
|
|
{ |
7
|
|
|
constructor() { |
8
|
|
|
this.client = services.appruve.client; |
9
|
|
|
this.apiKey = services.appruve.api_key; |
10
|
|
|
this.baseUrl = services.appruve.api_url; |
11
|
|
|
|
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Process axios calls |
16
|
|
|
* |
17
|
|
|
* @param {string} method The call method get|post|put|delete|patch |
18
|
|
|
* @param {string} url The url to call |
19
|
|
|
* @param {object|formData} payload The payload data to send with the call |
20
|
|
|
*/ |
21
|
|
|
process(method, url, payload) { |
22
|
|
|
//HttpProcessor class to handle axios calls |
23
|
|
|
let processor = new httpProcessor(this.baseUrl, this.apiKey, this.client); |
|
|
|
|
24
|
|
|
|
25
|
|
|
return processor.process(method, url, payload) |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Handles the ID request |
30
|
|
|
* |
31
|
|
|
* @param {object} IdFilter |
32
|
|
|
* @return {object} |
33
|
|
|
*/ |
34
|
|
|
async handle(IdFilter) |
35
|
|
|
{ |
36
|
|
|
if (!IdFilter.isSuccessful()) { |
|
|
|
|
37
|
|
|
|
38
|
|
|
const idType = IdFilter.getIDType().toUpperCase(); |
39
|
|
|
const country=IdFilter.getCountry().toLowerCase(); |
40
|
|
|
const type = this.getType(idType); |
41
|
|
|
const url = '/v1/verifications/' + country + '/' + type; |
42
|
|
|
|
43
|
|
|
const idNumber = IdFilter.getIDNumber(); |
44
|
|
|
const firstName = IdFilter.getFirstName(); |
45
|
|
|
const lastName = IdFilter.getLastName(); |
46
|
|
|
const middleName = IdFilter.getMiddleName(); |
47
|
|
|
const dateOfBirth = IdFilter.getDOB(); |
48
|
|
|
const phone = IdFilter.getPhoneNumber(); |
49
|
|
|
const expiryDate = IdFilter.getExpiry(); |
50
|
|
|
const gender = IdFilter.getGender(); |
51
|
|
|
const address = IdFilter.getAddress(); |
52
|
|
|
const pin = IdFilter.getPin(); |
53
|
|
|
const tin = IdFilter.getTin(); |
54
|
|
|
const full_name = IdFilter.getFullName(); |
55
|
|
|
const company = IdFilter.getCompany(); |
56
|
|
|
const registration_number = IdFilter.getRegistrationNumber(); |
57
|
|
|
|
58
|
|
|
const body = { |
59
|
|
|
'id' : idNumber, |
60
|
|
|
'first_name' : firstName, |
61
|
|
|
'last_name' : lastName, |
62
|
|
|
'middle_name' : middleName, |
63
|
|
|
'date_of_birth' : dateOfBirth, |
64
|
|
|
'phone_number' : phone, |
65
|
|
|
'expiry_date' : expiryDate, |
66
|
|
|
'gender' : gender, |
67
|
|
|
'address' : address, |
68
|
|
|
'pin' : pin, |
69
|
|
|
'tin' : tin, |
70
|
|
|
'full_name' : full_name, |
71
|
|
|
'company_name' : company, |
72
|
|
|
'registration_number' : registration_number |
73
|
|
|
}; |
74
|
|
|
|
75
|
|
|
try { |
76
|
|
|
const response = await this.process('POST', url, body); |
77
|
|
|
|
78
|
|
|
IdFilter.confirmSuccess(); |
79
|
|
|
|
80
|
|
|
IdFilter.setHandler(this.client); |
81
|
|
|
|
82
|
|
|
IdFilter.setData({ |
83
|
|
|
'handler' : IdFilter.getHandler(), |
84
|
|
|
'country' : IdFilter.getCountry().toUpperCase(), |
85
|
|
|
'message' : idType + ' Verified' + ' Successfully', |
86
|
|
|
'data' : response |
87
|
|
|
}); |
88
|
|
|
|
89
|
|
|
return IdFilter.getData(); |
90
|
|
|
|
91
|
|
|
} catch (error) { |
92
|
|
|
IdFilter.setError({'error' : error}); |
93
|
|
|
|
94
|
|
|
return IdFilter.getError(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Transform the ID |
102
|
|
|
* |
103
|
|
|
* @param {string} type |
104
|
|
|
* @return {string} |
105
|
|
|
*/ |
106
|
|
|
getType(type) |
107
|
|
|
{ |
108
|
|
|
if (type === constants.idValues.TYPE_NATIONAL_ID || type === constants.idValues.TYPE_NIN ) { |
109
|
|
|
return 'national_id'; |
110
|
|
|
} |
111
|
|
|
if (type === constants.idValues.TYPE_DRIVERS_LICENSE) { |
112
|
|
|
return 'driver_license'; |
113
|
|
|
} |
114
|
|
|
if (type === constants.idValues.TYPE_VOTER_CARD) { |
115
|
|
|
return 'voter'; |
116
|
|
|
} |
117
|
|
|
if (type === constants.idValues.TYPE_BVN) { |
118
|
|
|
return 'bvn'; |
119
|
|
|
} |
120
|
|
|
if (type === constants.idValues.TELCO_SUBSCRIBER) { |
121
|
|
|
return 'telco_subscriber'; |
122
|
|
|
} |
123
|
|
|
return type.toLowerCase(); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
module.exports = Appruve; |